interface Shape {
    draw(): void;
}

class Circle implements Shape {
    private color: string;
    private x: number = -Infinity;
    private y: number = -Infinity;
    private radius: number = 0;
    public constructor(color: string) {
        this.color = color;
    }
    public setLocation(x: number, y: number): void {
        this.x = x;
        this.y = y;
    }
    public setSize(radius: number): void {
        this.radius = radius;
    }
    public draw(): void {
        console.log(this);
    }
}

class ShapeFactory {
    private static readonly shapes: Map<string, Shape> = new Map<string, Shape>();
    public static getCircle(color: string): Circle {
        let circle: Circle = this.shapes.get(color) as Circle;
        if (circle === undefined) {
            circle = new Circle(color);
            this.shapes.set(color, circle);
            console.log(`Creating circle of color ${color}`);
        }
        return circle;
    }
}

function main() {
    const colors: string[] = ["red", "green", "blue", "yellow", "purple"];
    for (let i = 0; i < 10; i++) {
        const color: string = colors[i % colors.length];
        const circle: Circle = ShapeFactory.getCircle(color);
        circle.setLocation(i * 10, i * 10);
        circle.setSize(i * 2);
        circle.draw();
    }
}

main();
